package day19;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import org.junit.Test;


public class testDemo {
	@Test
	public void test1() {
		int[] array = {78, 45, 23, 56, 9, 31};
		for(int i = 1; i < array.length; i++) {
			for(int j = 0; j < array.length - 1; j++) {
				if(array[j] > array[j + 1]) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
				}
			}
		}
		for(int i = 0; i < array.length; i++) {
			System.out.print(array[i] + ",");
		}
	}
	
	@Test
	public void test2() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("输入一串字符：");
		String str = scanner.nextLine();
		char[] array = str.toCharArray();
		for(int i = 0; i < array.length; i++) {
			if(array[i] != array[array.length - i - 1]) {
				System.out.println(str + "不是回文");
				scanner.close();
				return;
			}
		}
		System.out.println(str + "是回文");
		scanner.close();
	}
	
	@Test
	public void test3() {
		// 默认运行的是主程序
		String name = Thread.currentThread().getName();
		System.out.println(name);// main
		
		// 通过继承一个Thread类启动一个线程
		MyThread myThread = new MyThread("MyThread");
		myThread.start();
		// 实现Runnable接口的方式启动一个线程
		MyRunnable myRunnable1 = new MyRunnable();
//		MyRunnable myRunnable2 = new MyRunnable();
//		MyRunnable myRunnable3 = new MyRunnable();
		Thread thread1 = new Thread(myRunnable1,"MyRunnable");
//		Thread thread2 = new Thread(myRunnable1,"MyRunnable2");
//		Thread thread3 = new Thread(myRunnable1,"MyRunnable3");
//		thread1.start();
//		thread2.start();
//		thread3.start();
	}
	
	@Test
	public void test4() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个非零整数");
		int getNum = scanner.nextInt();
		int factorial1 = result(getNum);
		int factorial2 = factorial(getNum);
		System.out.println(getNum +"!="+factorial2);
	}

	public int result(int n) {
		int result = 1;
		for(int i = n; i >= 1; i--) {
			result *= i;
		}
		
		System.out.println(n + "的阶乘=" + result);
		return 0;
	}
	
	private int factorial(int n) {
		if(n == 1) {
			return 1;
		}
		return n * factorial(n - 1);
	}
	
	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
//		long str = scanner.nextLong();
		String str = scanner.nextLine();
		switch(str) {
			case "王涵宇":
				System.out.println("我是傻逼");
				break;
			case "王瑞锞":
				System.out.println("王涵宇装装");
				break;
			default:
				break;
		}
	}
}
